package crowMessenger;

import java.util.ArrayList;

public class Accounts {
	protected static ArrayList<Account> accList = new ArrayList<Account>();

	protected static void makeList(){
		/*
		 * populate accounts from prefs and saved password from keyring and add to the 
		 * array list
		 */
	}

	protected static void addNew(Account acc){
		if(!isExist(acc))
			accList.add(acc);
	}

	protected static void remove(Account acc){
		if(acc.equals(null))
			return;
		if(isExist(acc))
			accList.remove(acc);
	}

	protected static int size(){
		return accList.size();
	}

	protected static ArrayList<Account> getAccountList(){
		return accList;
	}

	private static boolean isExist(Account acc){
		for(int i = 0; i < size(); i++){
			if(acc.getUser().equalsIgnoreCase(accList.get(i).getUser()))
				return true;
		}
		return false;
	}

	protected static Account search(String username){
		for(int i = 0; i < size(); i++){
			if(accList.get(i).getUser().equalsIgnoreCase(username))
				return accList.get(i);
		}
		return null;
	}

	protected static int getIndex(String username){
		for(int i = 0; i < size(); i++){
			if(accList.get(i).getUser().equalsIgnoreCase(username))
				return i;
		}
		return -1;
	}
}
